﻿using ReflectionStudio.Core.Events;
using System;
using System.ComponentModel;
using System.Data;
using System.Windows;
namespace WPFExcelReport
{
    public partial class TAPARTE
    {

        public TAPARTE()
        {
            if (DesignerProperties.GetIsInDesignMode(this))
                return;
            MV = new VAPARTE();
            this.DataContext = MV;
            InitializeComponent();
        }

        public override void vwMaster_CurrentChanged(object sender, EventArgs e)
        {
            base.vwMaster_CurrentChanged(sender, e);
            if(dwMaster==null)
            {
                VU1 = "";
            }
            else
            {
                switch (dwMaster["AMEMESCHL"].ToString().Trim())
                {
                    case "1":
                        VU1 =(1000*decimal.Parse(TMV.APAEWERTN)/1000/1000).ToString();
                        break;
                }
            }
        } 

       
        public override void OnEXAUFChg(string vlaue)
        {
            TBMain.Clear();
            if (EXAUF.Length < 48)
                return;
            dwData = TBMain.NewRow();
            dwData["APAEMANDANT"] = app.Mandant;
            dwData["APAEANRKRS"] = " AND APAEANRKRS='" + EXAUF.Substring(0,2) + "'";
            dwData["APAEALFDNR"] = " AND APAEALFDNR='"+ EXAUF.Substring(2, 6)+"'";
            dwData["APAEAFOLGE"] = " AND APAEAFOLGE='" + EXAUF.Substring(8, 3) + "'";
            dwData["APAEAEVOR"] = " AND APAEAEVOR='" + EXAUF.Substring(11, 4) + "'";
            SResult = TMV.QKSZ03(dwData);
            MergeData(SResult, false);
            if (!IsEdit)
                return;
            if (!IsAuto)
                return; 
            if (TBMain.Rows.Count > 0)
                return;
            //KEY = TMV.APAKANRKRS + TMV.APAKALFDNR + TMV.APAKAFOLGE + TMV.APAKAEVOR + TMV.APAKPKSTKRS + TMV.APAKPKST + TMV.APAKMTYP + TMV.APAKAGANG + TMV.APAKEVARHNR + TMV.APAKEVARUNR;
            if (EXAUF.Substring(21, 8).Trim() == "")
                return;
            if (EXAUF.Substring(44,4).Trim() == "")
                return;
            PM["MNRKRS"] = EXAUF.Substring(15, 2);
            PM["MLFDNR"] = EXAUF.Substring(17, 4);
            PM["MPOS"] = "  ";             
            PM["ANRKRS"] =  EXAUF.Substring(0, 2) ;
            PM["ALFDNR"] =  EXAUF.Substring(2, 6) ;
            PM["AFOLGE"] =  EXAUF.Substring(8, 3);
            PM["AEVOR"] =   EXAUF.Substring(11, 4);
            PM["KSTKRS"] = EXAUF.Substring(15, 2);
            PM["KST"] = EXAUF.Substring(17, 4);
            PM["MTYP"] = EXAUF.Substring(21, 8);
            PM["AGANG"] = EXAUF.Substring(29, 15);
            PM["EVARHNR"] = EXAUF.Substring(44,2);
            PM["EVARUNR"] = EXAUF.Substring(46,2);
            TMV.NEWAPE(PM);
            vwMaster.View.MoveCurrentToFirst();
            base.OnEXAUFChg(vlaue);
        }
 
    }
}
